package keke;

import java.util.Scanner;

class ArrayUtils1{
	public static double findMax(double[] arr,int begin, int end)throws IllegalArgumentException{
		
		if(begin>=end)
			throw new IllegalArgumentException("begin:"+begin+" >= end:"+end);
		else if(begin<0)
			throw new IllegalArgumentException("begin:"+begin+" < 0");
		else if(end>arr.length)
			throw new IllegalArgumentException("end:"+end+" > arr.length");
		double max=arr[begin];
		for(int i = begin;i<end;i++){
			if(max<arr[i])
				max=arr[i];
		}
		return max;
	}
}
public class Main0603 {
	public static void main(String[] args) throws IllegalArgumentException {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		double[] arr1=new double[n];
		for(int i=0;i<arr1.length;i++){
			arr1[i]=in.nextDouble();
		}
		while(in.hasNext()){
			double max;
			try{
				int begin=Integer.parseInt(in.next());
				int end=Integer.parseInt(in.next());
				max=ArrayUtils1.findMax(arr1,begin,end);
				System.out.println(max);
			}catch(NumberFormatException e){
				break;
			}
			catch(IllegalArgumentException e){	
				System.out.println(e);
			}
		}
		try {
		     System.out.println(ArrayUtils1.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
		} catch (Exception e1) {
		}
	}
}

